<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>修改</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all" <link rel="stylesheet"
        href="/html/main/config/lib/main.css" media="all">
</head>

<body id="layui-body-content" class="layui-bg">
    <div style="padding: 10px;">
        <form class="layui-form" action="" lay-filter="layui-form-Table">
            <table class="layui-table" align="center">
                <tr>
                    <td width="100">
                        请输入旧密码：
                    </td>
                    <td>
                        <input type="password" name="oldpassword" lay-verify="required" placeholder="请输入旧密码" autocomplete="off"
                            class="layui-input">
                    </td>
                </tr>
                <tr>
                    <td>
                        请输入新密码：
                    </td>
                    <td>
                        <input type="password" name="newpassword" lay-verify="required|pass" placeholder="请输入新密码" autocomplete="off"
                            class="layui-input">
                    </td>
                </tr>
                <tr>
                    <td>
                        请确认新密码：
                    </td>
                    <td>
                        <input type="password" name="confirmpassword" lay-verify="required|pass" placeholder="请确认新密码" autocomplete="off"
                            class="layui-input">
                    </td>
                </tr>
                <tr>
                    <td>
                        密码规则：
                    </td>
                    <td>
                        <span
                            style="color: red;">密码长度8位以上（包含8位），大写字母(至少一个)、小写字母(至少一个)、数字(至少一个)、特殊符号@&amp;%#_(至少一个)</span>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" align="center">
                        <button class=" layui-btn la yui-btn-normal" lay-submit lay-filter="YjbtnSave" id="YjbtnSave"
                            type="button">保存</button>
                    </td>
                </tr>
            </table>
        </form>
    </div>
    <script src="/layui/layui.js"></script>
    <script>
        layui.config({
            base: '/src/'
        }).use(['index', 'jm'], function () {
            var $ = layui.$,
                admin = layui.admin,
                main = layui.main,
                setter = layui.setter,
                layer = layui.layer,
                jm = layui.jm,
                form = layui.form;
            //自定义验证规则
            form.verify({
                //密码
                pass: [
                    /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$/
                    , '密码长度8位以上（包含8位），至少1个大写字母，1个小写字母，1个数字和一个特殊字符！'
                ]
            });

            //保存
            form.render().on('submit(YjbtnSave)', function (data) {

                if (data.field.newpassword != data.field.confirmpassword) {
                    main.msg_error("新密码和确认新密码不同！");
                    return;
                }
                if (data.field.oldpassword == data.field.newpassword) {
                    main.msg_error("新密码不能和旧密码相同！");
                    return;
                }

                admin.req({
                    url: 'sysUser/UpdatePwd'
                    , data: JSON.stringify({
                        old_passwd: jm.s4.encryptData_ECB(data.field.oldpassword),
                        new_passwd: jm.s4.encryptData_ECB(data.field.newpassword)
                    })
                    , type: 'put'
                    , contentType: 'application/json'
                    , done: function (res) {
                        if (res.successful) {
                            top.layer.confirm('密码修改成功，请重新登录！', {
                                btn: ['确定'] //按钮
                                , cancel: function () {
                                    layui.view.exit();
                                    top.location.href = '/';
                                }
                            }, function () {
                                layui.view.exit();
                                top.location.href = '/';
                            });
                        }
                        else {
                            main.msg_error(res.msg);
                        }
                    }
                });

            });

        });
    </script>

</body>

</html>